const path = require('path')
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')

module.exports = {
  outputDir: './build',
  // 项目打包时会从相对路径来获取相应js文件, 防止测试的时候找不到文件而报错
  // publicPath: './',
  chainWebpack: (config) => {
    config.resolve.alias
      .set('@', path.resolve(__dirname, 'src'))
      .set('views', '@/views')
    config
      .plugin('AutoImport')
      .use(AutoImport({ resolvers: [ElementPlusResolver()] }))
    config
      .plugin('Components')
      .use(Components({ resolvers: [ElementPlusResolver()] }))
  }
}

// 方法一
// module.exports = {
//   outputDir: './build',
//   configureWebpack: {
//     plugins: [
//       AutoImport({
//         resolvers: [ElementPlusResolver()]
//       }),
//       Components({
//         resolvers: [ElementPlusResolver()]
//       })
//     ],
//     resolve: {
//       alias: {
//         views: '@/views',
//         '@': path.resolve(__dirname, 'src')
//       }
//     }
//   }
// }
